package org.nokatag.tagjava;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;

public class Tab extends NokaTag{

	private static final long serialVersionUID = 7688260730679114929L;
	
	private String  tagId="a_tabbar";		// Tag name for the tab; must be uppercase
	private String tabWidth="130";		// Speed of the scroll
	private String tabHeight="400";	// Default height
	private String  defaultTab="a1";		// Default active tab=1 = 1st tab; 2 = 2nd tab; ..
	private String  tabstyle="modern";
	private String  tabtype="top";
	
	public int doStartTag() throws JspException {
		HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();
		String basePath = basepath(request);
		JspWriter jspOut = pageContext.getOut();
		StringBuilder bodystr = new StringBuilder();
		bodystr.append(potjs(request));
		bodystr.append(TableJS(request));
		String ntabWith = LenFormat(tabWidth);
		String ntabHeight = LenFormat(tabHeight);
		bodystr.append("<div id=\""+tagId+"\" style=\"width:"+ntabWith+"; height:"+ntabHeight+";\">");
		bodystr.append("<script>");
		bodystr.append("tabbar=new dhtmlXTabBar(\""+tagId+"\",\""+tabtype+"\");");
		bodystr.append("tabbar.setSkin('"+tabstyle+"');");
		bodystr.append("tabbar.setImagePath(\""+basePath+"/nokatag/tab/skins/\");");
		try {
			jspOut.write(bodystr.toString());
		} catch (IOException e) {
			e.printStackTrace();
		}
		return EVAL_BODY_INCLUDE;
	}
	public int doEndTag() throws JspException {
		try {
				pageContext.getOut().write("tabbar.setTabActive(\""+defaultTab+"\");</script></div>");
			} catch (IOException e) {
				e.printStackTrace();
			}
		return EVAL_PAGE;
		 }
	public String getTabtype() {
		return tabtype;
	}
	public void setTabtype(String tabtype) {
		this.tabtype = tabtype;
	}
	public String getDefaultTab() {
		return defaultTab;
	}
	public void setDefaultTab(String defaultTab) {
		this.defaultTab = defaultTab;
	}
	public String getTabHeight() {
		return tabHeight;
	}
	public void setTabHeight(String tabHeight) {
		this.tabHeight = tabHeight;
	}
	public String getTabstyle() {
		return tabstyle;
	}
	public void setTabstyle(String tabstyle) {
		this.tabstyle = tabstyle;
	}
	public String getTabWidth() {
		return tabWidth;
	}
	public void setTabWidth(String tabWidth) {
		this.tabWidth = tabWidth;
	}
	public String getTagId() {
		return tagId;
	}
	public void setTagId(String tagId) {
		this.tagId = tagId;
	}
	

	

}
